package com.example.bootredis.utils;

public class SynchronizedDemo2 {

    public static void main(String[] args) {
        final SynchronizedDemo2 test = new SynchronizedDemo2();
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                test.get(Thread.currentThread());
            }).start();
        }
/*
        new Thread(()->{
            test.get(Thread.currentThread());
        }).start();*/
    }

    public synchronized void get(Thread thread) {

        System.out.println(thread.getName() + "读操作睡觉");
        try {
            Thread.sleep(100);
        }catch (Exception e){

        }
        System.out.println(thread.getName() + "读的时候醒了");

    }
}
